#!/usr/local/bin/python
# This program performs "Hard Trim" on sequence and quality files checked by Lucy
# Usage: hard_trim.py seq.fasta.trim seq.qual.trim seq.clean.fasta seq.clean.qual

import sys
from Bio import SeqIO

seqs = SeqIO.parse(sys.argv[1], "fasta")
quals = SeqIO.parse(sys.argv[2], "qual")

outseq = open(sys.argv[3], "w")
outqual = open(sys.argv[4], "w")

for s, q in zip(seqs, quals):
    line = s.description.split(' ')
    start = int(line[-2])
    stop = int(line[-1])
    seq = s[start:stop].format("fasta")
    qual = q[start:stop].format("qual")
    outseq.write(seq)
    outqual.write(qual)

outseq.close()
outqual.close()
